package com.csproj.basic.repository.impl;


import com.csproj.basic.domain.Warehouse;
import com.csproj.basic.repository.custom.WarehouseRepositoryCustom;
import net.logstash.logback.encoder.org.apache.commons.lang.StringUtils;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.HashMap;
import java.util.Map;

/**
 * Spring Data JPA repository for the ClassInfo entity.
 */
@SuppressWarnings("unused")
public class WarehouseRepositoryImpl implements WarehouseRepositoryCustom {
    @PersistenceContext
    private EntityManager em;

    public EntityManager getEm() {
        return em;
    }

    /**
     * 机构分页查询方法
     * @param map	参数
     * @param pageable		分页对象
     * @return
     */
    public Page<Warehouse> findPageList(Map<String, Object> map, Pageable pageable) {
        //拼hql
        String hql = " from Warehouse wh where wh.deletedFlag = 0 ";
        String name = (String) map.get("houseName");
        Map<String,Object> queryParams = new HashMap<>();
        if (StringUtils.isNotBlank(name)) {
            hql += " and wh.houseName like :houseName";
            queryParams.put("houseName","%"+name+"%");
        }
        //查询
        Page<Warehouse> fieldList = query(hql, pageable, queryParams);
        //返回
        return fieldList;
    }

}
